home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!timbuk!cs.umn.edu!uc!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!sun-barr!newstop!sun!adobe.com!asente
- From: asente@adobe.com
- Newsgroups: comp.sources.x
- Subject: v10i044: Examples from New Xt Book, Part04/05
- Message-ID: <144424@sun.Eng.Sun.COM>
- Date: 1 Nov 90 05:52:31 GMT
- References: <csx-10i041:xt-examples@uunet.UU.NET>
- Sender: news@sun.Eng.Sun.COM
- Lines: 2264
- Approved: argv@sun.com
-
- Submitted-by: asente@adobe.com
- Posting-number: Volume 10, Issue 44
- Archive-name: xt-examples/part04
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # BarDisplay.c
- # Box.c
- # Confirm.c
- # Confirm1.c
- # Graph.c
- # GraphDispl.c
- # Label.c
- # This archive created: Wed Oct 24 14:25:38 1990
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'BarDisplay.c'" '(7808 characters)'
- if test -f 'BarDisplay.c'
- then
- echo shar: will not over-write existing file "'BarDisplay.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'BarDisplay.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "BarDisplaP.h" /* Bar display object */
- X#include "GraphP.h" /* Graph widget */
- X
- X#define Offset(field) XtOffsetOf(BarDisplayRec, barDisplay.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNspace, XtCSpace, XtRDimension, sizeof(Dimension),
- X Offset(space), XtRImmediate, (XtPointer) 5},
- X {XtNdefaultGraphWidth, XtCDefaultGraphWidth,
- X XtRDimension, sizeof(Dimension),
- X Offset(default_graph_width), XtRImmediate, (XtPointer) 200},
- X {XtNformat, XtCFormat, XtRString, sizeof(String),
- X Offset(format), XtRString, "%g"}
- X};
- X#undef Offset
- X
- X/* Forward declarations */
- X
- Xstatic void Initialize(), Redisplay(), ComputeSize();
- Xstatic Boolean SetValues();
- X
- X/* Class record declaration */
- X
- XBarDisplayClassRec barDisplayClassRec = {
- X /* Object class part */
- X {
- X /* superclass */ (WidgetClass) &graphDisplayClassRec,
- X /* class_name */ "BarDisplay",
- X /* widget_size */ sizeof(BarDisplayRec),
- X /* class_initialize */ NULL,
- X /* class_part_initialize */ NULL,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* obj1 */ NULL,
- X /* obj2 */ NULL,
- X /* obj3 */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* obj4 */ 0,
- X /* obj5 */ 0,
- X /* obj6 */ 0,
- X /* obj7 */ 0,
- X /* destroy */ NULL,
- X /* obj8 */ NULL,
- X /* obj9 */ NULL,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* obj10 */ NULL,
- X /* get_values_hook */ NULL,
- X /* obj11 */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* obj12 */ NULL,
- X /* obj13 */ NULL,
- X /* obj14 */ NULL,
- X /* extension */ NULL
- X },
- X /* GraphDisplay class part */
- X {
- X /* compute_size */ ComputeSize,
- X /* expose */ Redisplay,
- X /* extension */ NULL
- X },
- X /* BarDisplay class part */
- X {
- X /* extension */ NULL
- X }
- X};
- X
- X/* Class record pointer */
- X
- XWidgetClass barDisplayObjectClass = (WidgetClass) &barDisplayClassRec;
- X
- Xstatic void Initialize(request, new, args, num_args)
- X Widget request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X BarDisplayObject bd = (BarDisplayObject) new;
- X
- X /* Copy format */
- X bd->barDisplay.format = XtNewString(bd->barDisplay.format);
- X}
- X
- Xstatic Boolean SetValues(old, request, new, args, num_args)
- X Widget old, request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X BarDisplayObject oldbd = (BarDisplayObject) old;
- X BarDisplayObject newbd = (BarDisplayObject) new;
- X
- X#define NE(field) (oldbd->barDisplay.field != newbd->barDisplay.field)
- X
- X if (NE(format)) {
- X newbd->barDisplay.format =
- X XtNewString(newbd->barDisplay.format);
- X }
- X
- X /* If space or format has changed and we're realized, redisplay */
- X
- X if (NE(space) || NE(format)) {
- X
- X /* Kludge. There's no way to tell the Intrinsics to
- X automatically redisplay, so clear the parent, causing
- X expose events. Subclasses will do this too, but multiple
- X redisplays are avoided since the parent has
- X XtExposeCompressMultiple. */
- X
- X if (XtIsRealized(XtParent((Widget) newbd))) {
- X XClearArea(XtDisplayOfObject(newbd),
- X XtWindowOfObject(newbd), 0, 0, 0, 0, TRUE);
- X }
- X }
- X
- X return FALSE;
- X}
- X
- Xstatic void ComputeLabelDimensions(bd, label_w, total_w, height)
- X BarDisplayObject bd;
- X Dimension *label_w, *total_w, *height;
- X{
- X register XFontStruct *fs = bd->graphDisplay.font;
- X register int i;
- X int width;
- X GraphWidget parent = (GraphWidget) XtParent((Widget) bd);
- X char buf[100];
- X
- X *label_w = *total_w = 0;
- X if (parent->graph.labels != NULL) {
- X for (i = 0; i < parent->graph.num_entries; i++) {
- X width = XTextWidth(fs, parent->graph.labels[i],
- X strlen(parent->graph.labels[i]));
- X if (width > *label_w) *label_w = width;
- X }
- X }
- X
- X for (i = 0; i < parent->graph.num_entries; i++) {
- X (void) sprintf(buf, bd->barDisplay.format,
- X (float) parent->graph.values[i] / parent->graph.scale);
- X width = XTextWidth(fs, buf, strlen(buf));
- X if (width > *total_w) *total_w = width;
- X }
- X
- X *total_w += *label_w;
- X *height = fs->max_bounds.ascent + fs->max_bounds.descent;
- X}
- X
- Xstatic void ComputeSize(w)
- X GraphWidget w;
- X{
- X BarDisplayObject bd = (BarDisplayObject) w->composite.children[0];
- X Dimension label_width, total_width, label_height;
- X
- X ComputeLabelDimensions(bd, &label_width,
- X &total_width, &label_height);
- X
- X /* If parent has no width, compute one */
- X if (w->core.width == 0) {
- X w->core.width = 4*bd->barDisplay.space + total_width +
- X bd->barDisplay.default_graph_width;
- X }
- X
- X /* If parent has no height, compute one */
- X if (w->core.height == 0) {
- X w->core.height = w->graph.num_entries *
- X (bd->barDisplay.space + label_height) +
- X bd->barDisplay.space;
- X }
- X}
- X
- Xstatic void Redisplay(w, event, region)
- X GraphWidget w;
- X XEvent *event;
- X Region region;
- X{
- X BarDisplayObject bd = (BarDisplayObject) w->composite.children[0];
- X Dimension label_width, total_width, label_height;
- X Boolean displayBars;
- X register int i;
- X int x, y, bar_width;
- X char buf[100];
- X register int *values = w->graph.values;
- X register String *labels = w->graph.labels;
- X
- X ComputeLabelDimensions(bd, &label_width, &total_width,
- X &label_height);
- X
- X /* See if there's enough room to display bars */
- X
- X bar_width = w->core.width - total_width - 4*bd->barDisplay.space;
- X displayBars = (bar_width > (int) bd->barDisplay.space);
- X
- X y = bd->barDisplay.space;
- X for (i = 0; i < w->graph.num_entries; i++) {
- X if (labels != NULL) {
- X XDrawString(XtDisplay(w), XtWindow(w), bd->graphDisplay.gc,
- X bd->barDisplay.space,
- X y + bd->graphDisplay.font->max_bounds.ascent,
- X labels[i], strlen(labels[i]));
- X x = label_width + 2*bd->barDisplay.space;
- X } else x = 0;
- X
- X if (displayBars) {
- X XFillRectangle(XtDisplay(w), XtWindow(w),
- X bd->graphDisplay.gc, x, y,
- X bar_width * values[i] / w->graph.max_value,
- X bd->graphDisplay.font->max_bounds.ascent);
- X x += bar_width * values[i] / w->graph.max_value +
- X bd->barDisplay.space;
- X }
- X
- X (void) sprintf(buf, bd->barDisplay.format,
- X (float) values[i] / w->graph.scale);
- X XDrawString(XtDisplay(w), XtWindow(w), bd->graphDisplay.gc,
- X x, y + bd->graphDisplay.font->max_bounds.ascent,
- X buf, strlen(buf));
- X
- X y += label_height + bd->barDisplay.space;
- X }
- X}
- X
- SHAR_EOF
- if test 7808 -ne "`wc -c < 'BarDisplay.c'`"
- then
- echo shar: error transmitting "'BarDisplay.c'" '(should have been 7808 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Box.c'" '(8572 characters)'
- if test -f 'Box.c'
- then
- echo shar: will not over-write existing file "'Box.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Box.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "BoxP.h" /* Box private header file */
- X#include "LabelGadge.h" /* To check LabelGadgets */
- X
- X#define Offset(field) XtOffsetOf(BoxRec, box.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
- X Offset(margin), XtRImmediate, (XtPointer) 10},
- X};
- X
- X#undef Offset
- X
- X/* Forward declarations */
- X
- Xstatic void ChangeManaged(), Initialize(), InsertChild(),
- X DeleteChild(), Redisplay();
- Xstatic XtGeometryResult GeometryManager();
- Xstatic Boolean SetValues(), AcceptFocus();
- X
- Xstatic CompositeClassExtensionRec compositeExtension = {
- X /* next_extension */ NULL,
- X /* record_type */ NULLQUARK,
- X /* version */ XtCompositeExtensionVersion,
- X /* record_size */ sizeof(CompositeClassExtensionRec),
- X /* accepts_objects */ TRUE
- X};
- X
- XBoxClassRec boxClassRec = {
- X /* Core class part */
- X {
- X /* superclass */ (WidgetClass) &compositeClassRec,
- X /* class_name */ "Box",
- X /* widget_size */ sizeof(BoxRec),
- X /* class_initialize */ NULL,
- X /* class_part_initialize */ NULL,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* realize */ XtInheritRealize,
- X /* actions */ NULL,
- X /* num_actions */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* compress_motion */ TRUE,
- X /* compress_exposure */ XtExposeCompressMultiple,
- X /* compress_enterleave */ TRUE,
- X /* visible_interest */ FALSE,
- X /* destroy */ NULL,
- X /* resize */ NULL,
- X /* expose */ Redisplay,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* set_values_almost */ XtInheritSetValuesAlmost,
- X /* get_values_hook */ NULL,
- X /* accept_focus */ AcceptFocus,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* tm_table */ NULL,
- X /* query_geometry */ XtInheritQueryGeometry,
- X /* display_accelerator */ NULL,
- X /* extension */ NULL,
- X },
- X /* Composite class part */
- X {
- X /* geometry_manager */ GeometryManager,
- X /* change_managed */ ChangeManaged,
- X /* insert_child */ InsertChild,
- X /* delete_child */ DeleteChild,
- X /* extension */ (XtPointer) &compositeExtension,
- X },
- X /* Box class part */
- X {
- X /* extension */ NULL,
- X }
- X};
- X
- XWidgetClass boxWidgetClass = (WidgetClass) &boxClassRec;
- X
- Xstatic void DeleteChild(w)
- X Widget w;
- X{
- X BoxWidget box = (BoxWidget) XtParent(w);
- X
- X if (box->box.last_focus == w) box->box.last_focus = NULL;
- X
- X (*((CompositeWidgetClass)(boxWidgetClass->core_class.superclass))->
- X composite_class.delete_child) (w);
- X}
- X
- Xstatic void InsertChild(w)
- X Widget w;
- X{
- X String params[2];
- X Cardinal num_params;
- X Widget parent = XtParent(w);
- X
- X if (!XtIsWidget(w) && !XtIsSubclass(w, labelGadgetClass)) {
- X params[0] = XtClass(w)->core_class.class_name;
- X params[1] = XtClass(parent)->core_class.class_name;
- X num_params = 2;
- X XtAppErrorMsg(XtWidgetToApplicationContext(w),
- X "childError", "class", "WidgetError",
- X "Children of class %s cannot be added to %n widgets",
- X params, &num_params);
- X }
- X
- X (*((CompositeWidgetClass)(boxWidgetClass->core_class.superclass))->
- X composite_class.insert_child) (w);
- X}
- X
- Xstatic void Initialize(req, new, args, num_args)
- X Widget req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X ((BoxWidget) new)->box.last_focus = NULL;
- X}
- X
- Xstatic void CalculateNewSize(box, width, height)
- X BoxWidget box;
- X register Dimension *width, *height;
- X{
- X register Widget child;
- X register int i;
- X int right, bottom;
- X
- X *width = *height = 0;
- X
- X for (i = 0; i < box->composite.num_children; i++) {
- X child = box->composite.children[i];
- X if (!XtIsManaged(child)) continue;
- X right = child->core.x + child->core.width +
- X 2 * child->core.border_width;
- X bottom = child->core.y + child->core.height +
- X 2 * child->core.border_width;
- X if (right > (int) *width) *width = right;
- X if (bottom > (int) *height) *height = bottom;
- X }
- X
- X *width += box->box.margin;
- X *height += box->box.margin;
- X
- X if (*width == 0) *width = 1;
- X if (*height == 0) *height = 1;
- X}
- X
- Xstatic void ChangeManaged(w)
- X Widget w;
- X{
- X BoxWidget box = (BoxWidget) w;
- X XtWidgetGeometry request;
- X XtGeometryResult result;
- X
- X CalculateNewSize(box, &request.width, &request.height);
- X
- X if (request.width != box->core.width ||
- X request.height != box->core.height) {
- X request.request_mode = CWWidth | CWHeight;
- X do {
- X result = XtMakeGeometryRequest(w, &request, &request);
- X } while (result == XtGeometryAlmost);
- X }
- X}
- X
- Xstatic XtGeometryResult GeometryManager(w, desired, allowed)
- X Widget w;
- X XtWidgetGeometry *desired, *allowed;
- X{
- X BoxWidget box = (BoxWidget) XtParent(w);
- X XtWidgetGeometry request;
- X XtGeometryResult result;
- X
- X#define Wants(flag) (desired->request_mode & flag)
- X
- X if (Wants(XtCWQueryOnly)) return XtGeometryYes;
- X
- X if (Wants(CWWidth)) w->core.width = desired->width;
- X if (Wants(CWHeight)) w->core.height = desired->height;
- X if (Wants(CWX)) w->core.x = desired->x;
- X if (Wants(CWY)) w->core.y = desired->y;
- X if (Wants(CWBorderWidth)) {
- X w->core.border_width = desired->border_width;
- X }
- X
- X CalculateNewSize(box, &request.width, &request.height);
- X
- X if (request.width != box->core.width ||
- X request.height != box->core.height) {
- X request.request_mode = CWWidth | CWHeight;
- X do {
- X result = XtMakeGeometryRequest((Widget) box,
- X &request, &request);
- X } while (result == XtGeometryAlmost);
- X }
- X
- X return XtGeometryYes;
- X
- X#undef Wants
- X}
- X
- Xstatic Boolean SetValues(old, req, new, args, num_args)
- X Widget old, req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register BoxWidget oldbox = (BoxWidget) old;
- X register BoxWidget newbox = (BoxWidget) new;
- X
- X if (newbox->box.margin != oldbox->box.margin ||
- X newbox->core.width == 0 || newbox->core.height == 0) {
- X CalculateNewSize(newbox, &newbox->core.width,
- X &newbox->core.height);
- X }
- X
- X return FALSE;
- X}
- X
- Xstatic Boolean AcceptFocus(w, time)
- X Widget w;
- X Time *time;
- X{
- X BoxWidget box = (BoxWidget) w;
- X register int i;
- X
- X if (box->box.last_focus != NULL &&
- X XtIsManaged(box->box.last_focus)) {
- X if (XtCallAcceptFocus(box->box.last_focus, time)) {
- X return TRUE;
- X }
- X }
- X
- X for (i = 0; i < box->composite.num_children; i++) {
- X if (!XtIsManaged(box->composite.children[i])) continue;
- X if (XtCallAcceptFocus(box->composite.children[i], time)) {
- X box->box.last_focus = box->composite.children[i];
- X return TRUE;
- X }
- X }
- X
- X box->box.last_focus = NULL;
- X return FALSE;
- X}
- Xstatic void Redisplay(w, event, region)
- X Widget w;
- X XEvent *event;
- X Region region;
- X{
- X CompositeWidget comp = (CompositeWidget) w;
- X int i;
- X Widget c; /* child */
- X
- X for (i = 0; i < comp->composite.num_children; i++) {
- X c = comp->composite.children[i];
- X if (XtIsManaged(c) && XtIsSubclass(c, labelGadgetClass) &&
- X XRectInRegion(region, c->core.x, c->core.y,
- X c->core.width + 2*c->core.border_width,
- X c->core.height + 2*c->core.border_width)
- X != RectangleOut) {
- X (*(XtClass(c)->core_class.expose))(c, event, region);
- X }
- X }
- X}
- SHAR_EOF
- if test 8572 -ne "`wc -c < 'Box.c'`"
- then
- echo shar: error transmitting "'Box.c'" '(should have been 8572 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Confirm.c'" '(8763 characters)'
- if test -f 'Confirm.c'
- then
- echo shar: will not over-write existing file "'Confirm.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Confirm.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "ConfirmP.h" /* Confirm private header file */
- X#include "Label.h" /* Label public header file */
- X#include "Pushbutton.h" /* Pushbutton public header file */
- X
- X#define Offset(field) XtOffsetOf(ConfirmRec, confirm.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNlabel, XtCLabel, XtRString, sizeof(String),
- X Offset(label), XtRString, "Click to confirm"},
- X {XtNbuttonLabel, XtCButtonLabel, XtRString, sizeof(String),
- X Offset(button_label), XtRString, "OK"},
- X {XtNcallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
- X Offset(callback), XtRCallback, (XtPointer) NULL},
- X};
- X
- X#undef Offset
- X
- X#define LabelChild(w) (((CompositeWidget) w)->composite.children[0])
- X#define ButtonChild(w) (((CompositeWidget) w)->composite.children[1])
- X
- X/* Forward declarations */
- X
- Xstatic void InsertChild(), Initialize(), PositionChildren(),
- X GetValuesHook();
- Xstatic Boolean SetValues();
- Xstatic XtGeometryResult GeometryManager();
- X
- XConfirmClassRec confirmClassRec = {
- X /* Core class part */
- X {
- X /* superclass */ (WidgetClass) &boxClassRec,
- X /* class_name */ "Confirm",
- X /* widget_size */ sizeof(ConfirmRec),
- X /* class_initialize */ NULL,
- X /* class_part_initialize */ NULL,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* realize */ XtInheritRealize,
- X /* actions */ NULL,
- X /* num_actions */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* compress_motion */ TRUE,
- X /* compress_exposure */ XtExposeCompressMultiple,
- X /* compress_enterleave */ TRUE,
- X /* visible_interest */ FALSE,
- X /* destroy */ NULL,
- X /* resize */ PositionChildren,
- X /* expose */ NULL,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* set_values_almost */ XtInheritSetValuesAlmost,
- X /* get_values_hook */ GetValuesHook,
- X /* accept_focus */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* tm_table */ NULL,
- X /* query_geometry */ XtInheritQueryGeometry,
- X /* display_accelerator */ NULL,
- X /* extension */ NULL,
- X },
- X /* Composite class part */
- X {
- X /* geometry_manager */ GeometryManager,
- X /* change_managed */ XtInheritChangeManaged,
- X /* insert_child */ InsertChild,
- X /* delete_child */ XtInheritDeleteChild,
- X /* extension */ NULL,
- X },
- X /* Box class part */
- X {
- X /* extension */ NULL,
- X },
- X /* Confirm class part */
- X {
- X /* extension */ NULL,
- X }
- X};
- X
- XWidgetClass confirmWidgetClass = (WidgetClass) &confirmClassRec;
- X
- Xstatic void InsertChild(w)
- X Widget w;
- X{
- X String params[1];
- X Cardinal num_params;
- X CompositeWidget parent = (CompositeWidget) XtParent(w);
- X
- X if (parent->composite.num_children >= 2) {
- X params[0] = XtClass(parent)->core_class.class_name;
- X num_params = 1;
- X XtAppErrorMsg(XtWidgetToApplicationContext(w),
- X "childError", "number", "WidgetError",
- X "Applications cannot add children to %s widgets",
- X params, &num_params);
- X }
- X
- X (*((CompositeWidgetClass)(confirmWidgetClass->
- X core_class.superclass))->composite_class.insert_child) (w);
- X}
- X
- Xstatic void Callback(w, call_data, client_data)
- X Widget w;
- X XtPointer call_data, client_data;
- X{
- X ConfirmWidget confirm = (ConfirmWidget) XtParent(w);
- X
- X if (XtIsShell(XtParent(confirm))) XtPopdown(XtParent(confirm));
- X XtCallCallbackList(confirm, confirm->confirm.callback,
- X (XtPointer) NULL);
- X}
- X
- Xstatic void CalculateSize(cw, width, height)
- X ConfirmWidget cw;
- X Dimension *width, *height;
- X{
- X int label_width = LabelChild(cw)->core.width +
- X 2 * LabelChild(cw)->core.border_width,
- X button_width = ButtonChild(cw)->core.width +
- X 2 * ButtonChild(cw)->core.border_width,
- X max;
- X
- X max = label_width > button_width ? label_width : button_width;
- X
- X *width = max + 2 * cw->box.margin;
- X *height = LabelChild(cw)->core.height +
- X ButtonChild(cw)->core.height +
- X 2 * (LabelChild(cw)->core.border_width +
- X ButtonChild(cw)->core.border_width) +
- X 3 * cw->box.margin;
- X}
- X
- Xstatic void PositionChildren(cw)
- X ConfirmWidget cw;
- X{
- X int label_width = LabelChild(cw)->core.width +
- X 2 * LabelChild(cw)->core.border_width,
- X button_width = ButtonChild(cw)->core.width +
- X 2 * ButtonChild(cw)->core.border_width;
- X
- X XtMoveWidget(LabelChild(cw), (cw->core.width - label_width) / 2,
- X cw->box.margin);
- X XtMoveWidget(ButtonChild(cw), (cw->core.width - button_width) / 2,
- X 2 * cw->box.margin +
- X 2 * LabelChild(cw)->core.border_width +
- X LabelChild(cw)->core.height);
- X}
- X
- Xstatic void Initialize(req, new, args, num_args)
- X Widget req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X ConfirmWidget cw = (ConfirmWidget) new;
- X Arg arg[1];
- X
- X cw->confirm.label = XtNewString(cw->confirm.label);
- X XtSetArg(arg[0], XtNlabel, cw->confirm.label);
- X (void) XtCreateManagedWidget("label", labelWidgetClass,
- X new, arg, 1);
- X
- X cw->confirm.button_label = XtNewString(cw->confirm.button_label);
- X XtSetArg(arg[0], XtNlabel, cw->confirm.button_label);
- X (void) XtCreateManagedWidget("button", pushbuttonWidgetClass,
- X new, arg, 1);
- X XtAddCallback(ButtonChild(cw), XtNcallback, Callback, NULL);
- X
- X CalculateSize(cw, &cw->core.width, &cw->core.height);
- X PositionChildren(cw);
- X}
- X
- Xstatic void Destroy(w)
- X Widget w;
- X{
- X ConfirmWidget cw = (ConfirmWidget) w;
- X
- X XtFree((char *) cw->confirm.label);
- X XtFree((char *) cw->confirm.button_label);
- X}
- X
- Xstatic Boolean SetValues(old, req, new, args, num_args)
- X Widget old, req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register ConfirmWidget oldcw = (ConfirmWidget) old;
- X register ConfirmWidget newcw = (ConfirmWidget) new;
- X Arg arg[1];
- X Boolean resize = FALSE;
- X
- X#define NE(field) (oldcw->field != newcw->field)
- X
- X if (NE(confirm.label)) {
- X XtFree((char *) oldcw->confirm.label);
- X newcw->confirm.label = XtNewString(newcw->confirm.label);
- X XtSetArg(arg[0], XtNlabel, newcw->confirm.label);
- X XtSetValues(LabelChild(newcw), arg, 1);
- X resize = TRUE;
- X }
- X
- X if (NE(confirm.button_label)) {
- X XtFree((char *) oldcw->confirm.button_label);
- X newcw->confirm.button_label =
- X XtNewString(newcw->confirm.button_label);
- X XtSetArg(arg[0], XtNlabel, newcw->confirm.button_label);
- X XtSetValues(ButtonChild(newcw), arg, 1);
- X resize = TRUE;
- X }
- X
- X if (NE(box.margin) || resize) {
- X CalculateSize(newcw, &newcw->core.width, &newcw->core.height);
- X }
- X
- X return FALSE;
- X#undef NE
- X}
- X
- Xstatic void GetValuesHook(w, args, num_args)
- X Widget w;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register int i;
- X
- X for (i = 0; i < *num_args; i++) {
- X if (strcmp(args[i].name, XtNlabelWidget) == 0) {
- X *(Widget *) (args[i].value) = LabelChild(w);
- X } else if (strcmp(args[i].name, XtNbuttonWidget) == 0) {
- X *(Widget *) (args[i].value) = ButtonChild(w);
- X }
- X }
- X}
- X
- Xstatic XtGeometryResult GeometryManager(w, desired, allowed)
- X Widget w;
- X XtWidgetGeometry *desired, *allowed;
- X{
- X#define Wants(flag) (desired->request_mode & flag)
- X
- X if (Wants(CWWidth)) w->core.width = desired->width;
- X if (Wants(CWHeight)) w->core.height = desired->height;
- X if (Wants(CWX)) w->core.x = desired->x;
- X if (Wants(CWY)) w->core.y = desired->y;
- X if (Wants(CWBorderWidth)) {
- X w->core.border_width = desired->border_width;
- X }
- X
- X return XtGeometryYes;
- X
- X#undef Wants
- X}
- SHAR_EOF
- if test 8763 -ne "`wc -c < 'Confirm.c'`"
- then
- echo shar: error transmitting "'Confirm.c'" '(should have been 8763 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Confirm1.c'" '(7852 characters)'
- if test -f 'Confirm1.c'
- then
- echo shar: will not over-write existing file "'Confirm1.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Confirm1.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "Confirm1P.h" /* Confirm private header file */
- X#include "Label.h" /* Label public header file */
- X#include "Pushbutton.h" /* Pushbutton public header file */
- X
- X#define Offset(field) XtOffsetOf(ConfirmRec, confirm.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
- X Offset(margin), XtRImmediate, (XtPointer) 10},
- X {XtNlabel, XtCLabel, XtRString, sizeof(String),
- X Offset(label), XtRString, "Click to confirm"},
- X {XtNbuttonLabel, XtCButtonLabel, XtRString, sizeof(String),
- X Offset(button_label), XtRString, "OK"},
- X {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- X Offset(callback), XtRCallback, (XtPointer) NULL},
- X {XtNlabelWidget, XtCReadOnly, XtRWidget, sizeof(Widget),
- X Offset(label_widget), XtRImmediate, (XtPointer) NULL},
- X {XtNbuttonWidget, XtCReadOnly, XtRWidget, sizeof(Widget),
- X Offset(button_widget), XtRImmediate, (XtPointer) NULL}
- X};
- X
- X#undef Offset
- X
- X#define LabelChild(w) (((ConfirmWidget) w)->confirm.label_widget)
- X#define ButtonChild(w) (((ConfirmWidget) w)->confirm.button_widget)
- X
- X/* Forward declarations */
- X
- Xstatic void Initialize(), PositionChildren(), Realize(), Destroy();
- Xstatic Boolean SetValues();
- X
- XConfirmClassRec confirmClassRec = {
- X /* Core class part */
- X {
- X /* superclass */ (WidgetClass) &widgetClassRec,
- X /* class_name */ "Confirm",
- X /* widget_size */ sizeof(ConfirmRec),
- X /* class_initialize */ NULL,
- X /* class_part_initialize */ NULL,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* realize */ Realize,
- X /* actions */ NULL,
- X /* num_actions */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* compress_motion */ TRUE,
- X /* compress_exposure */ XtExposeCompressMultiple,
- X /* compress_enterleave */ TRUE,
- X /* visible_interest */ FALSE,
- X /* destroy */ Destroy,
- X /* resize */ PositionChildren,
- X /* expose */ NULL,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* set_values_almost */ XtInheritSetValuesAlmost,
- X /* get_values_hook */ NULL,
- X /* accept_focus */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* tm_table */ NULL,
- X /* query_geometry */ XtInheritQueryGeometry,
- X /* display_accelerator */ NULL,
- X /* extension */ NULL,
- X },
- X /* Confirm class part */
- X {
- X /* extension */ NULL,
- X }
- X};
- X
- XWidgetClass confirmWidgetClass = (WidgetClass) &confirmClassRec;
- X
- Xstatic void Callback(w, call_data, client_data)
- X Widget w;
- X XtPointer call_data, client_data;
- X{
- X ConfirmWidget confirm = (ConfirmWidget) XtParent(w);
- X
- X if (XtIsShell(XtParent(confirm))) XtPopdown(XtParent(confirm));
- X XtCallCallbackList(confirm, confirm->confirm.callback,
- X (XtPointer) NULL);
- X}
- X
- Xstatic void CalculateSize(cw, width, height)
- X ConfirmWidget cw;
- X Dimension *width, *height;
- X{
- X int label_width = LabelChild(cw)->core.width +
- X 2 * LabelChild(cw)->core.border_width,
- X button_width = ButtonChild(cw)->core.width +
- X 2 * ButtonChild(cw)->core.border_width,
- X max;
- X
- X max = label_width > button_width ? label_width : button_width;
- X
- X *width = max + 2 * cw->confirm.margin;
- X *height = LabelChild(cw)->core.height +
- X ButtonChild(cw)->core.height +
- X 2 * (LabelChild(cw)->core.border_width +
- X ButtonChild(cw)->core.border_width) +
- X 3 * cw->confirm.margin;
- X}
- X
- Xstatic void PositionChildren(cw)
- X ConfirmWidget cw;
- X{
- X int label_width = LabelChild(cw)->core.width +
- X 2 * LabelChild(cw)->core.border_width,
- X button_width = ButtonChild(cw)->core.width +
- X 2 * ButtonChild(cw)->core.border_width;
- X
- X XtMoveWidget(LabelChild(cw), (cw->core.width - label_width) / 2,
- X cw->confirm.margin);
- X XtMoveWidget(ButtonChild(cw), (cw->core.width - button_width) / 2,
- X 2 * cw->confirm.margin +
- X 2 * LabelChild(cw)->core.border_width +
- X LabelChild(cw)->core.height);
- X}
- X
- Xstatic void Initialize(req, new, args, num_args)
- X Widget req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X ConfirmWidget cw = (ConfirmWidget) new;
- X Arg arg[1];
- X
- X cw->confirm.label = XtNewString(cw->confirm.label);
- X XtSetArg(arg[0], XtNlabel, cw->confirm.label);
- X LabelChild(cw) = XtCreateWidget("label", labelWidgetClass,
- X new, arg, 1);
- X
- X cw->confirm.button_label = XtNewString(cw->confirm.button_label);
- X XtSetArg(arg[0], XtNlabel, cw->confirm.button_label);
- X ButtonChild(cw) = XtCreateWidget("button", pushbuttonWidgetClass,
- X new, arg, 1);
- X XtAddCallback(ButtonChild(cw), XtNcallback, Callback, NULL);
- X
- X CalculateSize(cw, &cw->core.width, &cw->core.height);
- X PositionChildren(cw);
- X}
- X
- Xstatic void Realize(w, valueMask, attributes)
- X Widget w;
- X XtValueMask *valueMask;
- X XSetWindowAttributes *attributes;
- X{
- X (*confirmWidgetClass->core_class.superclass->core_class.realize)
- X (w, valueMask, attributes);
- X XtRealizeWidget(LabelChild(w));
- X XtRealizeWidget(ButtonChild(w));
- X XMapSubwindows(XtDisplay(w), XtWindow(w));
- X}
- X
- Xstatic void Destroy(w)
- X Widget w;
- X{
- X ConfirmWidget cw = (ConfirmWidget) w;
- X
- X XtFree((char *) cw->confirm.label);
- X XtFree((char *) cw->confirm.button_label);
- X
- X XtDestroyWidget(LabelChild(w));
- X XtDestroyWidget(ButtonChild(w));
- X}
- X
- Xstatic Boolean SetValues(old, req, new, args, num_args)
- X Widget old, req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register ConfirmWidget oldcw = (ConfirmWidget) old;
- X register ConfirmWidget newcw = (ConfirmWidget) new;
- X Arg arg[1];
- X Boolean resize = FALSE;
- X
- X#define NE(field) (oldcw->field != newcw->field)
- X
- X /* We don't let these change */
- X LabelChild(newcw) = LabelChild(oldcw);
- X ButtonChild(newcw) = ButtonChild(oldcw);
- X
- X if (NE(confirm.label)) {
- X XtFree((char *) oldcw->confirm.label);
- X newcw->confirm.label = XtNewString(newcw->confirm.label);
- X XtSetArg(arg[0], XtNlabel, newcw->confirm.label);
- X XtSetValues(LabelChild(newcw), arg, 1);
- X resize = TRUE;
- X }
- X
- X if (NE(confirm.button_label)) {
- X XtFree((char *) oldcw->confirm.button_label);
- X newcw->confirm.button_label =
- X XtNewString(newcw->confirm.button_label);
- X XtSetArg(arg[0], XtNlabel, newcw->confirm.button_label);
- X XtSetValues(ButtonChild(newcw), arg, 1);
- X resize = TRUE;
- X }
- X
- X if (NE(confirm.margin) || resize) {
- X CalculateSize(newcw, &newcw->core.width, &newcw->core.height);
- X }
- X
- X return FALSE;
- X#undef NE
- X}
- SHAR_EOF
- if test 7852 -ne "`wc -c < 'Confirm1.c'`"
- then
- echo shar: error transmitting "'Confirm1.c'" '(should have been 7852 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Graph.c'" '(10709 characters)'
- if test -f 'Graph.c'
- then
- echo shar: will not over-write existing file "'Graph.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Graph.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "GraphP.h" /* Graph private header file */
- X#include "GraphDispP.h" /* Graph display object */
- X
- X#define Offset(field) XtOffsetOf(GraphRec, graph.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNnumEntries, XtCNumEntries, XtRInt, sizeof(int),
- X Offset(num_entries), XtRImmediate, (XtPointer) 0},
- X {XtNlabels, XtCLabels, XtRStringTable, sizeof(String *),
- X Offset(labels), XtRImmediate, (XtPointer) NULL},
- X {XtNvalues, XtCValues, XtRPointer, sizeof(int *),
- X Offset(values), XtRImmediate, (XtPointer) NULL},
- X {XtNmaxValue, XtCMaxValue, XtRInt, sizeof(int),
- X Offset(max_value), XtRImmediate, (XtPointer) 100},
- X {XtNscale, XtCScale, XtRInt, sizeof(int),
- X Offset(scale), XtRImmediate, (XtPointer) 1}
- X};
- X#undef Offset
- X
- X/* Forward declarations */
- X
- Xstatic void ClassInitialize(), Initialize(),
- X Redisplay(), Destroy(), Resize(), Realize(),
- X InsertChild();
- Xstatic Boolean SetValues();
- X
- Xstatic CompositeClassExtensionRec compositeExtension = {
- X /* next_extension */ NULL,
- X /* record_type */ NULLQUARK,
- X /* version */ XtCompositeExtensionVersion,
- X /* record_size */ sizeof(CompositeClassExtensionRec),
- X /* accepts_objects */ TRUE
- X};
- X
- XGraphClassRec graphClassRec = {
- X /* Core class part */
- X {
- X /* superclass */ (WidgetClass) &compositeClassRec,
- X /* class_name */ "Graph",
- X /* widget_size */ sizeof(GraphRec),
- X /* class_initialize */ ClassInitialize,
- X /* class_part_initialize */ NULL,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* realize */ Realize,
- X /* actions */ NULL,
- X /* num_actions */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* compress_motion */ TRUE,
- X /* compress_exposure */ XtExposeCompressMultiple,
- X /* compress_enterleave */ TRUE,
- X /* visible_interest */ FALSE,
- X /* destroy */ Destroy,
- X /* resize */ Resize,
- X /* expose */ Redisplay,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* set_values_almost */ XtInheritSetValuesAlmost,
- X /* get_values_hook */ NULL,
- X /* accept_focus */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* tm_table */ NULL,
- X /* query_geometry */ NULL,
- X /* display_accelerator */ NULL,
- X /* extension */ NULL
- X },
- X /* Composite class part */
- X {
- X /* geometry_manager */ NULL,
- X /* change_managed */ NULL,
- X /* insert_child */ InsertChild,
- X /* delete_child */ XtInheritDeleteChild,
- X /* extension */ (XtPointer) &compositeExtension,
- X },
- X /* Graph class part */
- X {
- X /* extension */ NULL
- X }
- X};
- X
- X/* Class record pointer */
- X
- XWidgetClass graphWidgetClass = (WidgetClass) &graphClassRec;
- X
- Xstatic Boolean CvtStringToStringList(dpy, args, num_args,
- X from, to, data)
- X Display *dpy;
- X XrmValuePtr args;
- X Cardinal *num_args;
- X XrmValuePtr from, to;
- X XtPointer *data;
- X{
- X register int i, count = 1;
- X register char *ch, *start = from->addr;
- X static String *list;
- X int len;
- X
- X if (*num_args != 0) {
- X XtAppErrorMsg(XtDisplayToApplicationContext(dpy),
- X "cvtStringToStringList", "wrongParameters",
- X "XtToolkitError",
- X "String to string list conversion needs no extra arguments",
- X (String *) NULL, (Cardinal *) NULL);
- X }
- X if (to->addr != NULL && to->size < sizeof(String *)) {
- X to->size = sizeof(String *);
- X return FALSE;
- X }
- X if (start == NULL || *start == '\0') list = NULL;
- X else {
- X for (ch = start; *ch != '\0'; ch++) { /* Count strings */
- X if (*ch == '\n') count++;
- X }
- X list = (String *) XtCalloc(count+1, sizeof(String));
- X
- X for (i = 0; i < count; i++) {
- X for (ch = start; *ch != '\n' && *ch != '\0'; ch++) {}
- X len = ch - start;
- X list[i] = XtMalloc(len + 1);
- X (void) strncpy(list[i], start, len);
- X list[i][len] = '\0';
- X start = ch + 1;
- X }
- X }
- X if (to->addr == NULL) to->addr = (caddr_t) &list;
- X else *(String **) to->addr = list;
- X to->size = sizeof(String *);
- X return TRUE;
- X}
- X
- Xstatic void StringListDestructor(app, to, converter_data,
- X args, num_args)
- X XtAppContext app;
- X XrmValuePtr to;
- X XtPointer converter_data;
- X XrmValuePtr args;
- X Cardinal *num_args;
- X{
- X String *list = (String *) to->addr;
- X register String *entry;
- X
- X if (list == NULL) return;
- X
- X for (entry = list; entry != NULL; entry++) {
- X XtFree((XtPointer) entry);
- X }
- X
- X XtFree((XtPointer) list);
- X}
- X
- Xstatic void ClassInitialize()
- X{
- X /* Register a converter for string to string list */
- X
- X XtSetTypeConverter(XtRString, XtRStringTable,
- X CvtStringToStringList, (XtConvertArgList) NULL, 0,
- X XtCacheAll | XtCacheRefCount, StringListDestructor);
- X}
- X
- Xstatic void Initialize(request, new, args, num_args)
- X Widget request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register GraphWidget gw = (GraphWidget) new;
- X int *values;
- X register int i;
- X String label;
- X
- X /* Copy the values */
- X values = (int *) XtCalloc(gw->graph.num_entries, sizeof(int));
- X for (i = 0; i < gw->graph.num_entries; i++) {
- X values[i] = gw->graph.values[i];
- X }
- X gw->graph.values = values;
- X
- X /* If labels is not NULL, make sure there are enough of them now
- X to avoid an error some random other place. */
- X if (gw->graph.labels != NULL) {
- X for (i = 0; i < gw->graph.num_entries; i++) {
- X label = gw->graph.labels[i];
- X }
- X }
- X}
- X
- Xstatic Boolean SetValues(old, req, new, args, num_args)
- X Widget old, req, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X register GraphWidget oldgraph = (GraphWidget) old;
- X register GraphWidget newgraph = (GraphWidget) new;
- X int *values;
- X String label;
- X register int i;
- X
- X#define NE(field) (newgraph->graph.field != oldgraph->graph.field)
- X#define EQ(field) (newgraph->graph.field == oldgraph->graph.field)
- X
- X if (NE(values)) {
- X values = (int *) XtCalloc(newgraph->graph.num_entries,
- X sizeof(int));
- X XtFree(oldgraph->graph.values);
- X for (i = 0; i < newgraph->graph.num_entries; i++) {
- X values[i] = newgraph->graph.values[i];
- X }
- X newgraph->graph.values = values;
- X return TRUE;
- X }
- X
- X /* If num_entries changed but not the labels or values,
- X something's wrong */
- X if (NE(num_entries) && (EQ(labels) || EQ(values))) {
- X XtAppErrorMsg(XtWidgetToApplicationContext(new),
- X "countError", "numEntries", "WidgetError",
- X "Number of graph entries changed but not labels or values",
- X (String *) NULL, (Cardinal *) NULL);
- X }
- X
- X if (NE(labels) && newgraph->graph.labels != NULL) {
- X for (i = 0; i < newgraph->graph.num_entries; i++) {
- X label = newgraph->graph.labels[i];
- X }
- X }
- X
- X return NE(num_entries) || NE(labels) || NE(max_value);
- X#undef NE
- X}
- X
- Xstatic void Destroy(w)
- X Widget w;
- X{
- X GraphWidget gw = (GraphWidget) w;
- X
- X XtFree((char *) gw->graph.values);
- X}
- X
- Xstatic void InsertChild(w)
- X Widget w;
- X{
- X String params[2];
- X Cardinal num_params;
- X CompositeWidget parent = (CompositeWidget) XtParent(w);
- X GraphDisplayObjectClass childClass;
- X
- X if (!XtIsSubclass(w, graphDisplayObjectClass)) {
- X params[0] = XtClass(w)->core_class.class_name;
- X params[1] = XtClass(parent)->core_class.class_name;
- X num_params = 2;
- X XtAppErrorMsg(XtWidgetToApplicationContext(w),
- X "childError", "class", "WidgetError",
- X "Children of class %s cannot be added to %n widgets",
- X params, &num_params);
- X }
- X
- X if (parent->composite.num_children != 0) {
- X params[0] = XtClass(parent)->core_class.class_name;
- X num_params = 1;
- X XtAppErrorMsg(XtWidgetToApplicationContext(w),
- X "childError", "number", "WidgetError",
- X "%s widgets can only take one child",
- X params, &num_params);
- X }
- X
- X (*((CompositeWidgetClass)(graphWidgetClass->
- X core_class.superclass))->composite_class.insert_child) (w);
- X
- X /* Give the child a chance to compute our dimensions */
- X
- X childClass = (GraphDisplayObjectClass) XtClass(w);
- X if (childClass->graphDisplay_class.compute_size != NULL) {
- X (*childClass->graphDisplay_class.compute_size) (parent);
- X }
- X}
- X
- Xstatic void Realize(w, valueMask, attributes)
- X Widget w;
- X XtValueMask *valueMask;
- X XSetWindowAttributes *attributes;
- X{
- X GraphWidget gw = (GraphWidget) w;
- X String params[2];
- X Cardinal num_params;
- X
- X if (gw->composite.num_children != 1) {
- X params[0] = XtClass(w)->core_class.class_name;
- X num_params = 1;
- X XtAppErrorMsg(XtWidgetToApplicationContext(w),
- X "childError", "number", "WidgetError",
- X "%s widgets must have exactly one child",
- X params, &num_params);
- X }
- X
- X (*graphWidgetClass->core_class.superclass->core_class.realize)
- X (w, valueMask, attributes);
- X}
- X
- Xstatic void Redisplay(w, event, region)
- X Widget w;
- X XEvent *event;
- X Region region;
- X{
- X GraphWidget gw = (GraphWidget) w;
- X GraphDisplayObject d =
- X (GraphDisplayObject) gw->composite.children[0];
- X GraphDisplayObjectClass childClass;
- X
- X childClass = (GraphDisplayObjectClass) XtClass((Widget) d);
- X if (childClass->graphDisplay_class.expose != NULL) {
- X (*childClass->graphDisplay_class.expose) (w, event, region);
- X }
- X}
- Xstatic void Resize(w)
- X Widget w;
- X{
- X /* If widget is realized, clear and redisplay */
- X
- X if (XtIsRealized(w)) {
- X XClearWindow(XtDisplay(w), XtWindow(w));
- X (*(XtClass(w)->core_class.expose))(w,
- X (XEvent *) NULL, (Region) NULL);
- X }
- X}
- SHAR_EOF
- if test 10709 -ne "`wc -c < 'Graph.c'`"
- then
- echo shar: error transmitting "'Graph.c'" '(should have been 10709 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'GraphDispl.c'" '(5482 characters)'
- if test -f 'GraphDispl.c'
- then
- echo shar: will not over-write existing file "'GraphDispl.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'GraphDispl.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include "GraphDispP.h" /* Graph display object */
- X
- X#define Offset(field) XtOffsetOf(GraphDisplayRec, graphDisplay.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
- X Offset(font), XtRString, (XtPointer) XtDefaultFont},
- X {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
- X Offset(foreground), XtRString,
- X (XtPointer) XtDefaultForeground},
- X};
- X#undef Offset
- X
- X/* Forward declarations */
- X
- Xstatic void ClassPartInitialize(), Initialize(), Destroy();
- Xstatic Boolean SetValues();
- X
- X/* Class record declaration */
- X
- XGraphDisplayClassRec graphDisplayClassRec = {
- X /* Object class part */
- X {
- X /* superclass */ (WidgetClass) &objectClassRec,
- X /* class_name */ "GraphDisplay",
- X /* widget_size */ sizeof(GraphDisplayRec),
- X /* class_initialize */ NULL,
- X /* class_part_initialize */ ClassPartInitialize,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* obj1 */ NULL,
- X /* obj2 */ NULL,
- X /* obj3 */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* obj4 */ 0,
- X /* obj5 */ 0,
- X /* obj6 */ 0,
- X /* obj7 */ 0,
- X /* destroy */ Destroy,
- X /* obj8 */ NULL,
- X /* obj9 */ NULL,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* obj10 */ NULL,
- X /* get_values_hook */ NULL,
- X /* obj11 */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* obj12 */ NULL,
- X /* obj13 */ NULL,
- X /* obj14 */ NULL,
- X /* extension */ NULL
- X },
- X /* GraphDisplay class part */
- X {
- X /* compute_size */ NULL,
- X /* expose */ NULL,
- X /* extension */ NULL
- X }
- X};
- X
- X/* Class record pointer */
- X
- XWidgetClass graphDisplayObjectClass =
- X (WidgetClass) &graphDisplayClassRec;
- X
- Xstatic void ClassPartInitialize(widgetClass)
- X WidgetClass widgetClass;
- X{
- X register GraphDisplayObjectClass wc =
- X (GraphDisplayObjectClass) widgetClass;
- X GraphDisplayObjectClass super =
- X (GraphDisplayObjectClass) wc->object_class.superclass;
- X
- X if (wc->graphDisplay_class.compute_size == InheritComputeSize) {
- X wc->graphDisplay_class.compute_size =
- X super->graphDisplay_class.compute_size;
- X }
- X
- X if (wc->graphDisplay_class.expose == XtInheritExpose) {
- X wc->graphDisplay_class.expose =
- X super->graphDisplay_class.expose;
- X }
- X}
- X
- Xstatic GC GetGC(gd)
- X GraphDisplayObject gd;
- X{
- X XGCValues values;
- X
- X /* Allocate a graphics context with the foreground and font */
- X
- X values.foreground = gd->graphDisplay.foreground;
- X values.font = gd->graphDisplay.font->fid;
- X
- X return XtGetGC(XtParent((Widget) gd),
- X GCForeground | GCFont, &values);
- X}
- X
- Xstatic void Initialize(request, new, args, num_args)
- X Widget request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X GraphDisplayObject gd = (GraphDisplayObject) new;
- X
- X /* Get a graphics context */
- X gd->graphDisplay.gc = GetGC(gd);
- X}
- X
- Xstatic Boolean SetValues(old, request, new, args, num_args)
- X Widget old, request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X GraphDisplayObject oldgd = (GraphDisplayObject) old;
- X GraphDisplayObject newgd = (GraphDisplayObject) new;
- X
- X#define NE(field) (oldgd->field != newgd->field)
- X
- X /* If foreground or font has changed, update GC */
- X
- X if (NE(graphDisplay.foreground) || NE(graphDisplay.font->fid)) {
- X XtReleaseGC(newgd, oldgd->graphDisplay.gc);
- X newgd->graphDisplay.gc = GetGC(newgd);
- X
- X /* Kludge. There's no way to tell the Intrinsics to
- X automatically redisplay, so clear the parent, causing
- X expose events. Subclasses will do this too, but multiple
- X redisplays are avoided since the parent has
- X XtExposeCompressMultiple. */
- X
- X if (XtIsRealized(XtParent((Widget) newgd))) {
- X XClearArea(XtDisplayOfObject(newgd),
- X XtWindowOfObject(newgd), 0, 0, 0, 0, TRUE);
- X }
- X }
- X
- X return FALSE;
- X#undef NE
- X}
- Xstatic void Destroy(w)
- X Widget w;
- X{
- X GraphDisplayObject gd = (GraphDisplayObject) w;
- X
- X XtReleaseGC(XtParent(w), gd->graphDisplay.gc);
- X}
- SHAR_EOF
- if test 5482 -ne "`wc -c < 'GraphDispl.c'`"
- then
- echo shar: error transmitting "'GraphDispl.c'" '(should have been 5482 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Label.c'" '(16084 characters)'
- if test -f 'Label.c'
- then
- echo shar: will not over-write existing file "'Label.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Label.c'
- X/***********************************************************
- XCopyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute these examples for any
- Xpurpose and without fee is hereby granted, provided that the above
- Xcopyright notice appear in all copies and that both that copyright
- Xnotice and this permission notice appear in supporting documentation,
- Xand that the name of Digital not be used in advertising or publicity
- Xpertaining to distribution of the software without specific, written
- Xprior permission.
- X
- XDIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- XSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- XOR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- XOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- XOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- XOR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X#include <X11/Xos.h> /* Needed for string manipulation */
- X#include <X11/IntrinsicP.h> /* Intrinsics header file */
- X#include <X11/StringDefs.h> /* Resource string definitions */
- X#include <X11/Xatom.h> /* For selection atoms */
- X#include "LabelP.h" /* Label private header file */
- X
- X#define Offset(field) XtOffsetOf(LabelRec, label.field)
- X
- Xstatic XtResource resources[] = {
- X {XtNlabel, XtCLabel, XtRString, sizeof(String),
- X Offset(label), XtRString, (XtPointer) NULL},
- X {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
- X Offset(font), XtRString, (XtPointer) XtDefaultFont},
- X {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
- X Offset(foreground), XtRString,
- X (XtPointer) XtDefaultForeground},
- X {XtNjustify, XtCJustify, XtRJustify, sizeof(Justify),
- X Offset(justify), XtRImmediate, (XtPointer) Left},
- X {XtNspace, XtCSpace, XtRDimension, sizeof(Dimension),
- X Offset(space), XtRImmediate, (XtPointer) 2},
- X {XtNloseSelection, XtCLoseSelection, XtRCallback,
- X sizeof(XtCallbackList), Offset(lose_selection),
- X XtRCallback, (XtPointer) NULL},
- X {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
- X XtOffsetOf(LabelRec, core.border_width),
- X XtRImmediate, (XtPointer) 0},
- X};
- X#undef Offset
- X
- X/* Forward declarations */
- X
- Xstatic void ClassInitialize(), ClassPartInitialize(), Initialize(),
- X Redisplay(), Destroy(), Resize(), LoseSelection();
- Xstatic Boolean SetValues(), SelectText();
- Xstatic XtGeometryResult QueryGeometry();
- X
- X/* Class record declaration */
- X
- XLabelClassRec labelClassRec = {
- X /* Core class part */
- X {
- X /* superclass */ (WidgetClass) &widgetClassRec,
- X /* class_name */ "Label",
- X /* widget_size */ sizeof(LabelRec),
- X /* class_initialize */ ClassInitialize,
- X /* class_part_initialize */ ClassPartInitialize,
- X /* class_inited */ FALSE,
- X /* initialize */ Initialize,
- X /* initialize_hook */ NULL,
- X /* realize */ XtInheritRealize,
- X /* actions */ NULL,
- X /* num_actions */ 0,
- X /* resources */ resources,
- X /* num_resources */ XtNumber(resources),
- X /* xrm_class */ NULLQUARK,
- X /* compress_motion */ TRUE,
- X /* compress_exposure */ XtExposeCompressMultiple,
- X /* compress_enterleave */ TRUE,
- X /* visible_interest */ FALSE,
- X /* destroy */ Destroy,
- X /* resize */ Resize,
- X /* expose */ Redisplay,
- X /* set_values */ SetValues,
- X /* set_values_hook */ NULL,
- X /* set_values_almost */ XtInheritSetValuesAlmost,
- X /* get_values_hook */ NULL,
- X /* accept_focus */ NULL,
- X /* version */ XtVersion,
- X /* callback offsets */ NULL,
- X /* tm_table */ NULL,
- X /* query_geometry */ QueryGeometry,
- X /* display_accelerator */ NULL,
- X /* extension */ NULL
- X },
- X /* Label class part */
- X {
- X /* select */ SelectText,
- X /* extension */ NULL
- X }
- X};
- X
- X/* Class record pointer */
- X
- XWidgetClass labelWidgetClass = (WidgetClass) &labelClassRec;
- X
- Xstatic Boolean LowerCase(from, to, size)
- X register String from, to;
- X int size;
- X{
- X register char ch;
- X register int i;
- X
- X for (i = 0; i < size; i++) {
- X ch = from[i];
- X if (ch >= 'A' && ch <= 'Z') to[i] = ch - 'A' + 'a';
- X else to[i] = ch;
- X if (ch == '\0') return FALSE;
- X }
- X return TRUE;
- X}
- X
- XBoolean CvtStringToJustify(dpy, args, num_args, from, to, data)
- X Display *dpy;
- X XrmValuePtr args;
- X Cardinal *num_args;
- X XrmValuePtr from, to;
- X XtPointer *data;
- X{
- X#define LOWER_SIZE 10
- X char lower[LOWER_SIZE]; /* Lower cased string value */
- X register int i;
- X Boolean badConvert;
- X static Justify j;
- X
- X if (*num_args != 0) { /* Check for correct number */
- X XtAppErrorMsg(XtDisplayToApplicationContext(dpy),
- X "cvtStringToJustify", "wrongParameters",
- X "XtToolkitError",
- X "String to justify conversion needs no extra arguments",
- X (String *) NULL, (Cardinal *) NULL);
- X }
- X
- X /* Lower case the value */
- X badConvert = LowerCase(from->addr, lower, LOWER_SIZE);
- X
- X /* Try to convert if a short enough string specified */
- X if (!badConvert) {
- X if (strcmp(lower, "left") == 0) j = Left;
- X else if (strcmp(lower, "center") == 0) j = Center;
- X else if (strcmp(lower, "right") == 0) j = Right;
- X else badConvert = TRUE;
- X }
- X
- X /* String too long or unknown value -- issue warning */
- X if (badConvert) {
- X XtDisplayStringConversionWarning(dpy, from->addr, "Justify");
- X } else {
- X if (to->addr == NULL) to->addr = (caddr_t) &j;
- X else if (to->size < sizeof(Justify)) badConvert = TRUE;
- X else *(Justify *) to->addr = j;
- X
- X to->size = sizeof(Justify);
- X }
- X return !badConvert;
- X#undef LOWER_SIZE
- X}
- X
- X#if 0
- XBoolean CvtStringToJustify(dpy, args, num_args, from, to, data)
- X Display *dpy;
- X XrmValuePtr args;
- X Cardinal *num_args;
- X XrmValuePtr from, to;
- X XtPointer *data;
- X{
- X#define LOWER_SIZE 10
- X char lower[LOWER_SIZE]; /* Lower cased string value */
- X register int i;
- X Boolean badConvert;
- X XrmQuark q;
- X static Justify j;
- X static XrmQuark Qleft, Qcenter, Qright;
- X static Boolean haveQuarks = FALSE;
- X
- X if (*num_args != 0) { /* Check for correct number */
- X XtAppErrorMsg(XtDisplayToApplicationContext(dpy),
- X "cvtStringToJustify", "wrongParameters",
- X "XtToolkitError",
- X "String to justify conversion needs no extra arguments",
- X (String *) NULL, (Cardinal *) NULL);
- X }
- X
- X if (!haveQuarks) {
- X Qleft = XrmStringToQuark("left");
- X Qcenter = XrmStringToQuark("center");
- X Qright = XrmStringToQuark("right");
- X haveQuarks = TRUE;
- X }
- X
- X badConvert = LowerCase(from->addr, lower, LOWER_SIZE);
- X
- X /* Try to convert if a short enough string specified */
- X
- X if (!badConvert) {
- X q = XrmStringToQuark(lower);
- X if (q == Qleft) j = Left;
- X else if (q == Qcenter) j = Center;
- X else if (q == Qright) j = Right;
- X else badConvert = TRUE;
- X }
- X
- X /* String too long or unknown value -- issue warning */
- X
- X if (badConvert) {
- X XtDisplayStringConversionWarning(dpy, from->addr, "Justify");
- X } else {
- X if (to->addr == NULL) to->addr = (caddr_t) &j;
- X else if (to->size < sizeof(Justify)) badConvert = TRUE;
- X else *(Justify *) to->addr = j;
- X
- X to->size = sizeof(Justify);
- X }
- X return !badConvert;
- X#undef LOWER_SIZE
- X}
- X#endif
- X
- Xstatic Atom FetchAtom(w, name)
- X Widget w;
- X String name;
- X{
- X Atom a;
- X XrmValue source, dest;
- X
- X source.size = strlen(name)+1;
- X source.addr = name;
- X dest.size = sizeof(Atom);
- X dest.addr = (caddr_t) &a;
- X
- X (void) XtConvertAndStore(w, XtRString, &source, XtRAtom, &dest);
- X return a;
- X}
- X
- Xstatic Boolean DeliverSelection(w, selection, target,
- X type, value, length, format)
- X Widget w;
- X Atom *selection, *target, *type;
- X XtPointer *value;
- X unsigned long *length;
- X int *format;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X static Atom targets = 0;
- X
- X if (targets == 0) {
- X targets = FetchAtom(w, "TARGETS");
- X }
- X
- X if (*target == targets) {
- X *type = XA_ATOM;
- X *value = (XtPointer) XtNew(Atom);
- X *(Atom *) *value = XA_STRING;
- X *length = 1;
- X *format = 32;
- X return TRUE;
- X }
- X
- X if (*target == XA_STRING) {
- X *type = XA_STRING;
- X *value = (XtPointer) XtNewString(lw->label.label);
- X *length = lw->label.label_len;
- X *format = 8;
- X return TRUE;
- X }
- X
- X return FALSE;
- X}
- X
- Xstatic void LoseSelection(w, selection)
- X Widget w;
- X Atom *selection;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X
- X XtCallCallbackList(lw, lw->label.lose_selection,
- X (XtPointer) selection);
- X}
- X
- X/* Label's select implementation */
- X
- Xstatic Boolean SelectText(w, selection, own)
- X Widget w;
- X Atom selection;
- X Boolean own;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X
- X if (own) {
- X return XtOwnSelection(w, selection,
- X XtLastTimestampProcessed(XtDisplay(w)),
- X DeliverSelection, LoseSelection,
- X (XtSelectionDoneProc) NULL);
- X } else {
- X XtDisownSelection(w, selection,
- X XtLastTimestampProcessed(XtDisplay(w)));
- X return TRUE;
- X }
- X}
- X
- XBoolean LabelSelectText(w, selection, own)
- X Widget w;
- X Atom selection;
- X Boolean own;
- X{
- X /* Check that we're in Label or a subclass */
- X
- X XtCheckSubclass(w, labelWidgetClass, NULL);
- X
- X /* Call the class method */
- X
- X return (*((LabelWidgetClass) XtClass(w))->label_class.select)
- X (w, selection, own);
- X}
- X
- Xstatic void ClassInitialize()
- X{
- X /* Register a converter for string to justification */
- X
- X XtSetTypeConverter(XtRString, XtRJustify, CvtStringToJustify,
- X (XtConvertArgList) NULL, 0,
- X XtCacheAll, (XtDestructor) NULL);
- X}
- X
- Xstatic void ClassPartInitialize(widget_class)
- X WidgetClass widget_class;
- X{
- X register LabelWidgetClass wc = (LabelWidgetClass) widget_class;
- X LabelWidgetClass super =
- X (LabelWidgetClass) wc->core_class.superclass;
- X
- X if (wc->label_class.select == InheritSelectText) {
- X wc->label_class.select = super->label_class.select;
- X }
- X}
- X
- Xstatic void SetTextWidthAndHeight(lw)
- X register LabelWidget lw;
- X{
- X register XFontStruct *fs = lw->label.font;
- X int accel_len;
- X
- X lw->label.label_len = strlen(lw->label.label);
- X lw->label.label_width =
- X XTextWidth(fs, lw->label.label, lw->label.label_len);
- X lw->label.label_height =
- X fs->max_bounds.ascent + fs->max_bounds.descent;
- X
- X if (lw->label.accel_string != NULL) {
- X accel_len = strlen(lw->label.accel_string);
- X lw->label.label_len += accel_len;
- X lw->label.label_width +=
- X XTextWidth(fs, lw->label.accel_string, accel_len);
- X }
- X}
- X
- Xstatic GC GetNormalGC(lw)
- X LabelWidget lw;
- X{
- X XGCValues values;
- X
- X /* Allocate a graphics context with the foreground and font */
- X
- X values.foreground = lw->label.foreground;
- X values.font = lw->label.font->fid;
- X return XtGetGC((Widget) lw, GCForeground | GCFont, &values);
- X}
- X
- Xstatic void Initialize(request, new, args, num_args)
- X Widget request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X LabelWidget lw = (LabelWidget) new;
- X
- X /* If no label is specified, use the name */
- X if (lw->label.label == NULL) lw->label.label = lw->core.name;
- X
- X /* Copy the label */
- X lw->label.label = XtNewString(lw->label.label);
- X
- X /* Clear accelerator string */
- X lw->label.accel_string = NULL;
- X
- X /* Compute the text dimensions and get a graphics context. */
- X SetTextWidthAndHeight(lw);
- X lw->label.gc = lw->label.current_gc = GetNormalGC(lw);
- X
- X /* If no size specified, compute one */
- X lw->label.size_computed =
- X (lw->core.width == 0) && (lw->core.height == 0);
- X
- X if (lw->core.width == 0) {
- X lw->core.width = lw->label.label_width + 2 * lw->label.space;
- X }
- X if (lw->core.height == 0) {
- X lw->core.height = lw->label.label_height + 2 * lw->label.space;
- X }
- X
- X lw->label.desired_width = lw->core.width;
- X lw->label.desired_height = lw->core.height;
- X}
- X
- Xstatic Boolean SetValues(old, request, new, args, num_args)
- X Widget old, request, new;
- X ArgList args;
- X Cardinal *num_args;
- X{
- X LabelWidget oldlw = (LabelWidget) old;
- X LabelWidget newlw = (LabelWidget) new;
- X Boolean redisplay = FALSE;
- X
- X#define NE(field) (oldlw->field != newlw->field)
- X
- X /* If the label has been reset to NULL, change to the name */
- X
- X if (newlw->label.label == NULL) {
- X newlw->label.label = newlw->core.name;
- X }
- X
- X /* Decide whether to compute the size */
- X
- X if (newlw->core.width == 0 && newlw->core.height == 0) {
- X newlw->label.size_computed = TRUE;
- X } else if (NE(core.width) || NE(core.height)) {
- X newlw->label.size_computed = FALSE;
- X if (NE(core.width)) {
- X newlw->label.desired_width = newlw->core.width;
- X }
- X if (NE(core.height)) {
- X newlw->label.desired_height = newlw->core.height;
- X }
- X } /* else leave the same */
- X
- X /* If label, font, or accelerator string has changed,
- X compute size and recopy */
- X
- X if (NE(label.label) || NE(label.font) || NE(label.accel_string)) {
- X SetTextWidthAndHeight(newlw);
- X redisplay = TRUE;
- X
- X if (NE(label.label)) {
- X XtFree((char *) oldlw->label.label);
- X newlw->label.label = XtNewString(newlw->label.label);
- X }
- X
- X if (NE(label.accel_string)) {
- X XtFree((char *) oldlw->label.accel_string);
- X newlw->label.accel_string =
- X XtNewString(newlw->label.accel_string);
- X }
- X }
- X
- X /* Compute the size if necessary */
- X
- X if ((newlw->label.size_computed && redisplay) ||
- X newlw->core.width == 0) {
- X newlw->label.desired_width = newlw->core.width =
- X newlw->label.label_width + 2 * newlw->label.space;
- X }
- X if ((newlw->label.size_computed && redisplay) ||
- X newlw->core.height == 0) {
- X newlw->label.desired_height = newlw->core.height =
- X newlw->label.label_height + 2 * newlw->label.space;
- X }
- X
- X /* If foreground or font has changed, update GC */
- X
- X if (NE(label.foreground) || NE(label.font->fid)) {
- X XtReleaseGC(newlw, oldlw->label.gc);
- X newlw->label.gc = GetNormalGC(newlw);
- X
- X if (newlw->label.current_gc == oldlw->label.gc) {
- X newlw->label.current_gc = newlw->label.gc;
- X redisplay = TRUE;
- X }
- X }
- X
- X return redisplay || NE(label.space) || NE(label.justify);
- X#undef NE
- X}
- X
- Xstatic void Destroy(w)
- X Widget w;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X
- X XtFree((char *) lw->label.label);
- X XtReleaseGC(w, lw->label.gc);
- X}
- X
- Xstatic void Redisplay(w, event, region)
- X Widget w;
- X XEvent *event;
- X Region region;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X char *string;
- X Boolean allocated = FALSE;
- X int x;
- X
- X if (lw->label.accel_string == NULL) {
- X string = lw->label.label;
- X } else {
- X string = XtMalloc(lw->label.label_len + 1);
- X (void) strcpy(string, lw->label.label);
- X (void) strcat(string, lw->label.accel_string);
- X allocated = TRUE;
- X }
- X
- X switch (lw->label.justify) {
- X case Left:
- X x = lw->label.space;
- X break;
- X case Right:
- X x = (int) lw->core.width - (int) lw->label.space -
- X (int) lw->label.label_width;
- X break;
- X case Center:
- X x = ((int) lw->core.width -
- X (int) lw->label.label_width) / 2;
- X break;
- X }
- X
- X XDrawString(XtDisplay(w), XtWindow(w), lw->label.current_gc,
- X x, lw->label.space + lw->label.font->max_bounds.ascent,
- X string, lw->label.label_len);
- X
- X if (allocated) XtFree(string);
- X}
- X
- Xstatic void Resize(w)
- X Widget w;
- X{
- X /* If widget is realized, clear and redisplay */
- X
- X if (XtIsRealized(w)) {
- X XClearWindow(XtDisplay(w), XtWindow(w));
- X (*(XtClass(w)->core_class.expose))(w,
- X (XEvent *) NULL, (Region) NULL);
- X }
- X}
- X
- Xstatic XtGeometryResult QueryGeometry(w, proposed, desired)
- X Widget w;
- X XtWidgetGeometry *proposed, *desired;
- X{
- X LabelWidget lw = (LabelWidget) w;
- X#define Set(bit) (proposed->request_mode & bit)
- X
- X desired->width = lw->label.desired_width;
- X desired->height = lw->label.desired_height;
- X desired->request_mode = CWWidth | CWHeight;
- X
- X if (Set(CWWidth) && proposed->width == desired->width &&
- X Set(CWHeight) && proposed->height == desired->height) {
- X return XtGeometryYes;
- X }
- X
- X if (desired->width == lw->core.width &&
- X desired->height == lw->core.height) {
- X return XtGeometryNo;
- X }
- X return XtGeometryAlmost;
- X#undef Set
- X}
- SHAR_EOF
- if test 16084 -ne "`wc -c < 'Label.c'`"
- then
- echo shar: error transmitting "'Label.c'" '(should have been 16084 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-
- dan
- ----------------------------------------------------
- O'Reilly && Associates argv@sun.com / argv@ora.com
- Opinions expressed reflect those of the author only.
-